Repository navigation
[feat] canvas: copy pasted media between canvases on the server - #82
Merged
Merged
Conversation
A cross-canvas paste uploaded each copied file from the page and then
downloaded it again for the preview, so every image crossed the browser's
connection twice. Over a remote port forward a 4 MB image took seconds.
PUT /api/creation/projects/{id}/uploads/{handle}/copy now stages another
project's verified asset as an upload in the target project, without its
bytes leaving the server. It takes the expected fingerprint and refuses a
source that changed. Registration still goes through asset.import, so the
copy is an ordinary upload with the same file checks and replay rules.
A paste copies saved media this way, finding the source asset by its
recorded ID or, for a node that has just been imported, by its preview
URL. Unsaved media, or a source that changed or is gone, is uploaded from
the bytes captured at copy. The preview reuses those bytes instead of
reading the new asset back.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: princepride <wangzhipeng628@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#80 修好了跨画布粘贴,但素材仍经过浏览器中转:浏览器先把复制的文件上传到目标工程,登记后为了显示预览再下载一遍。通过远程端口转发访问时,一张 4 MB 的图片要几秒才能粘贴完成。本 PR 改为在服务器上复制素材,粘贴过程中浏览器不收发任何素材字节。
新接口。
PUT /api/creation/projects/{id}/uploads/{handle}/copy,请求体为{projectId, assetId, fingerprint?}。UploadInfo。asset.import登记。复制结果就是目标工程里的一次普通上传,来源记为upload,复用同一套文件探测、大小限制、同句柄重放和冲突规则,不新增命令或契约。fingerprint时,若来源素材内容已变化,返回 409,不复制新内容。粘贴流程。
Test Plan / Result
本地工作树:Python 3.12、Node.js 24.22.1,Python 命令使用
PYTHONPATH=packages/core/src:apps/api/src。浏览器使用隔离 API/Vite 和 Chromium,启动方式见docs/development/validation.md。python -m pytest tests/test_creation_assets.py -qnode --test tests/clipboardMedia.test.tsnode tests/browser/cross_canvas_paste.mjs(已在 CI 中)PUT …/uploads/<id>/copy,没有素材上传或/content下载;保存、再次粘贴复用、重新打开后仍可读取npm testnpm run build、python scripts/generate_contracts.py --checkpython -m pytest tests -qtest_runtime_readiness::test_runtime_catalog_can_skip_probes_and_check_one_harness与test_tool_lifecycle::test_another_live_worker_is_not_marked_interrupted在本环境的main(5581f19f)上同样失败耗时。 在 Chromium 中用 CDP 将网络限制为上下行各 16 Mbit/s、延迟 40 ms,模拟远程端口转发,粘贴一张刚上传的 4 MB PNG,测量从粘贴到图片显示的时间:
Known issues / Validation limits
copyCanvasSource)仍经浏览器中转,可在后续改用此接口。🤖 Generated with Claude Code